import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:flutter_taotaoshipin/common/theme/app_colors.dart';
import 'package:flutter_taotaoshipin/util/image_utils.dart';
import 'package:flutter_taotaoshipin/widget/load_image.dart';

class DramaBigRankingCard extends StatefulWidget {
  const DramaBigRankingCard({
    super.key,
    this.cover,
    this.title,
    this.type,
    this.desc,
    this.index,
    this.followOnTap,
    this.playOnTap,
    this.isFollowing = false,
  });

  final String? cover;
  final String? title;
  final String? type;
  final String? desc;
  final int? index;
  final Function()? followOnTap;
  final Function()? playOnTap;
  final bool isFollowing;

  @override
  State<DramaBigRankingCard> createState() => _DramaBigRankingCardState();
}

class _DramaBigRankingCardState extends State<DramaBigRankingCard> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: widget.playOnTap,
      child: Stack(
        children: [
          Positioned(
            left: 0,
            top: 44,
            right: 0,
            bottom: 0,
            child: Container(
              alignment: Alignment.centerRight,
              decoration: BoxDecoration(
                color:
                    widget.isFollowing ? Color(0xFF888888) : AppColors.app_main,
                borderRadius:
                    BorderRadius.horizontal(right: Radius.circular(8)),
              ),
              child: GestureDetector(
                onTap: () {
                  widget.followOnTap?.call();
                },
                child: Padding(
                  padding: const EdgeInsets.fromLTRB(11, 10, 5, 10),
                  child: LoadAssetImage(
                    widget.isFollowing
                        ? 'home/ranking/zhui_sel'
                        : 'home/ranking/zhui',
                    width: 22,
                    height: 22,
                  ),
                ),
              ),
            ),
          ),
          Positioned(
            left: 0,
            top: 44,
            right: 32,
            bottom: 0,
            child: Container(
              decoration: BoxDecoration(
                color: Color(0xFFECEDF1),
                borderRadius:
                    BorderRadius.horizontal(right: Radius.circular(8)),
              ),
            ),
          ),
          Row(
            children: [
              Padding(
                padding: const EdgeInsets.only(top: 5),
                child: AspectRatio(
                  aspectRatio: 80 / 111,
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(8),
                    child: LoadImage(widget.cover ?? ''),
                  ),
                ),
              ),
              SizedBox(width: 10),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    SizedBox(height: 15.6),
                    Text(
                      widget.title ?? '',
                      style: TextStyle(
                        color: Color(0xFF333333),
                        fontSize: 16,
                        fontWeight: FontWeight.bold,
                      ),
                      maxLines: 1,
                    ),
                    SizedBox(height: 15.6),
                    Row(
                      children: [
                        Expanded(
                          child: Text(
                            widget.desc ?? '',
                            style: TextStyle(
                              color: Color(0xFF333333).withOpacity(0.6),
                              fontSize: 12,
                            ),
                            maxLines: 3,
                            overflow: TextOverflow.ellipsis,
                          ),
                        ),
                        SizedBox(width: 38),
                      ],
                    ),
                  ],
                ),
              ),
            ],
          ),
          Stack(
            alignment: Alignment.center,
            children: [
              LoadAssetImage(
                widget.index! < 5
                    ? 'home/ranking/top${widget.index! + 1}'
                    : 'home/ranking/topOther',
                width: 27,
              ),
              Positioned(
                left: 2.2,
                top: 3,
                right: 2.2,
                child: Text(
                  '${widget.index! + 1}'.padLeft(2, '0'),
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 14,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
